﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Wrapper
{
    public class CodeUtils
    {
        public static string CheckCode(string codeResult)
        {
            string result = "";
            if (codeResult.StartsWith("-"))
            {
                result = "错误值为：" + codeResult;
            }
            else if (codeResult.Length != 3)
            {
                result = "识别错误，当前识别内容为：" + codeResult;
            }
            else if (!IsChinese(codeResult))
            {
                result = "非中文,当前识别内容为：" + codeResult;
            }
            return result;
        }

        public static bool IsChinaString(string CString)
        {
            bool BoolValue = false;
            for (int i = 0; i < CString.Length; i++)
            {
                if (Convert.ToInt32(Convert.ToChar(CString.Substring(i, 1))) < Convert.ToInt32(Convert.ToChar(128)))
                {
                    BoolValue = false;
                }
                else
                {

                    return BoolValue = true;
                }
            }

            return BoolValue;

        }

        public static bool IsChinese(string CString)
        {
            return Regex.IsMatch(CString, @"^[\u4e00-\u9fa5]+$");
        }
    }
}
